import api from '@/api';
import { showToastMsg } from '@/utils/format.js';

const users = {
	state: {
		usersInfo: {}
	},
	mutations: {
		SAVE_USERS_INFO(state, usersInfo) {
			state.usersInfo = usersInfo;
		}
	},
	actions: {
		save_usersInfo({ commit }, usersInfo) {
			commit('SAVE_USERS_INFO', usersInfo)
		},
		/**
		 * @description: 获取用户信息
		 * @param {*} 
		 * @return {*}
		 */
		async get_userInfo({ commit, dispatch }){
			let token = uni.getStorageSync('ccxiplatformtoken')
			if(token) {
				let result = await api.getUserInfo({token})
				result.code == 200 && dispatch('save_usersInfo', result.data)
				
			} else {
				showToastMsg('请重新登陆')
				uni.navigateTo({ url: '/pages/login/index' })
			}
		}
	}
}

export default users;